package com.intel.bluetooth;

import com.intel.surface.ThreadUtil;
import com.intel.surface.UnconnectDevicePn;
import lombok.Data;

import javax.bluetooth.RemoteDevice;

@Data
public class DeviceConnectService {
    private Boolean going, run;

    private RemoteDevice remoteDevice;
    private UnconnectDevicePn unconnectDevicePn;

    public DeviceConnectService(UnconnectDevicePn unconnectDevicePn) {
        this.unconnectDevicePn = unconnectDevicePn;
        this.remoteDevice = unconnectDevicePn.getRemoteDevice();
    }

    public void connect() {
        going = true;
        run = false;
        ThreadUtil.execute(new Runnable() {
            @Override
            public void run() {
                while (going) {
                    if (!run) {
                        ConnectService connectService = new ConnectService(unconnectDevicePn, DeviceConnectService.this);
                        connectService.start();
                    }

                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }
}
